package com.yunchao.qrcode

data class InvoiceInfoModel(
    val fixedIdentifier: String,    // 固定标识
    val invoiceTypeCode: String,    // 发票种类代码
    val invoiceCode: String,        // 发票代码
    val invoiceNumber: String?,     // 发票号码（可为空）
    val amount: String,             // 开票金额
    val date: String,               // 开票日期（YYYYMMDD）
    val checkCode: String?,         // 发票校验码（可为空）
    val encryptionCode: String?     // 加密字符（可为空）
){
    companion object{

        // 解析示例
        fun parseInvoice(raw: String): InvoiceInfoModel? {
            val parts = raw.split(",")
            if (parts.size < 8) return null

            return InvoiceInfoModel(
                fixedIdentifier = parts[0],
                invoiceTypeCode = parts[1],
                invoiceCode = parts[2],
                invoiceNumber = parts[3].takeIf { it.isNotEmpty() },
                amount = parts[4],
                date = parts[5],
                checkCode = parts[6].takeIf { it.isNotEmpty() },
                encryptionCode = parts[7].takeIf { it.isNotEmpty() }
            )
        }
    }
}

